
package com.feib.soeasy.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.feib.soeasy.dao.CommissionCodeTableDao;
import com.feib.soeasy.dao.FormatDefinitionDao;
import com.feib.soeasy.dao.GroupDao;
import com.feib.soeasy.dao.MenuItemDao;
import com.feib.soeasy.dao.RealAccountDao;
import com.feib.soeasy.dao.RoleDao;
import com.feib.soeasy.dao.UserDao;
import com.feib.soeasy.model.ColumnDefinition;
import com.feib.soeasy.model.CommissionCodeTable;
import com.feib.soeasy.model.FormatDefinition;
import com.feib.soeasy.model.Group;
import com.feib.soeasy.model.MenuItem;
import com.feib.soeasy.model.Role;
import com.feib.soeasy.model.User;
import com.feib.soeasy.pagination.PaginatedList;
import com.feib.soeasy.service.GroupService;


/**
 * @title (#)GroupServiceImpl.java<br>
 * @description 帳單業者基本資料邏輯物件<br>
 * @author Jimmy Liu<br>
 * @version 1.0.0 2010/11/25
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2010/11/19 create by Jimmy Liu<br>
 */
@Service("groupService")
public class GroupServiceImpl extends BaseServiceImpl implements GroupService {

    @Resource(name="groupDao")
    private GroupDao groupDao;

    @Resource(name="realAccountDao")
    private RealAccountDao realAccountDao;

    @Resource(name="userDao")
    private UserDao userDao;

    @Resource(name="roleDao")
    private RoleDao roleDao;

    @Resource(name="formatDefinitionDao")
    private FormatDefinitionDao formatDefinitionDao;

    @Resource(name="reportTemplateDirectory")
    private String reportTemplateDirectory;

    @Resource(name="commissionCodeTableDao")
    private CommissionCodeTableDao commissionCodeTableDao;

    @Resource(name="menuItemDao")
    private MenuItemDao menuItemDao;
    

    /**
     * 依據查詢物件查詢帳單業者
     * @param payment 查詢條件
     * @param paginationConfig 換頁、排序條件
     * @return 查詢結果物件
     */
    @Override
    public PaginatedList<Group> queryByGroup(Group group, PaginatedList<Group> paginationConfig) {
        return groupDao.queryPaginationByGroup(group, paginationConfig);
    }
    

    /**
     * 依據查詢物件查詢帳單業者,排除銀行端資料
     * @param group 查詢條件
     * @param paginationConfig 換頁、排序條件
     * @return 查詢結果物件
     */
    @Override
    public PaginatedList<Group> queryByGroupExcludeBank(Group group, PaginatedList<Group> paginationConfig) {
        return groupDao.queryPaginationByGroupExcludeBank(group, paginationConfig);
    }
    
    /**
     * 依據業者代號(unique key)取得帳單業者物件
     * @param groupNo 業者代號
     * @return 帳單業者物件
     */
    public Group findByExactGroupNo(String groupNo)
    {
        return groupDao.getGroupByGroupNo(groupNo);
    }
    
    public PaginatedList<Group> queryPaginationByGroupvirtualAccountNo(Group group, String accountNo, PaginatedList<Group> paginationConfig)
    {
        return groupDao.queryPaginationByGroupvirtualAccountNo(group, accountNo, paginationConfig);
    }


    /* (non-Javadoc)
     * @see com.feib.soeasy.service.GroupService#queryByPk(java.lang.Long)
     */
    @Override
    public Group queryByPk(Long groupPk) {
        return groupDao.findByPk(groupPk);
    }


    /* (non-Javadoc)
     * @see com.feib.soeasy.service.GroupService#isDuplicateGroupNo(java.lang.String)
     */
    @Override
    public boolean isDuplicateGroupNo(String groupNo) {
        return null != groupDao.findByGroupNo(groupNo);
    }


    /* (non-Javadoc)
     * @see com.feib.soeasy.service.GroupService#save(com.feib.soeasy.model.Group)
     */
    @Override
    public Group save(Group group) {
        Group result = groupDao.save(group);
        return result;
    }
    
    @Override
    public void updateAmount(Group group)
    {
    	groupDao.updateAmount(group);
    }
    
    @Override
    public void updateLevel(Group group)
    {
    	groupDao.updateLevel(group);
    }
    /*
     * (non-Javadoc)
     * @see com.feib.soeasy.service.GroupService#addGroup(com.feib.soeasy.model.Group)
     */
    public Group addGroup(Group group)
    {
        groupDao.save(group);
        
        // 新增ADMIN 帳號
        User user = new User();
        user.setGroup(group);
        user.setUserId("admin");
        user.setUserPassWord("4a7d1ed414474e4033ac29ccb8653d9b"); //default pwd: 0000
        user.setUserName("系統管理者");
        user.setUserEmail(group.getContactEmail());
        user.setUserPhone(group.getContactTelNo());
        if (null == user.getUserPhone())
            user.setUserPhone(group.getContactCellNo());
        user.setEnabled(Boolean.TRUE);
        user.setLocked(Boolean.FALSE);
        user.setPwdExpiredDate(new Date()); // 強迫下次登入要變更密碼
        userDao.save(user);
        
        // 新增 ADMINISTRATOR Role
        Role role = new Role();
        role.setGroup(group);
        role.setRoleNo("ADMINISTRATOR");
        role.setRoleName("系統管理角色");
        
        role.setUsers(new HashSet<User>());
        role.getUsers().add(user);
        
        role.setMenuItems(new HashSet<MenuItem>());
        List<MenuItem> adminMenuItems = menuItemDao.getNoneBankAdminMenu();
        for (MenuItem adminMenuItem : adminMenuItems)
        {
            //System.out.println(adminMenuItem.getMenuId()+": " +adminMenuItem.getMenuItemPk());
            //MenuItem item = new MenuItem();
            //item.setMenuItemPk(adminMenuItem.getMenuItemPk()); // SOEZ9000 系統管理
            role.getMenuItems().add(adminMenuItem);
        }
        /*
        MenuItem item = new MenuItem();
        item.setMenuItemPk(new Long(5)); // SOEZ9000 系統管理
        role.getMenuItems().add(item);
        
        item = new MenuItem();
        item.setMenuItemPk(new Long(28));// SOEZ9001 帳號維護作業
        role.getMenuItems().add(item);
        
        item = new MenuItem();
        item.setMenuItemPk(new Long(29));// SOEZ9002 角色維護作業
        role.getMenuItems().add(item);
        
        
        item = new MenuItem();
        item.setMenuItemPk(new Long(33));// SOEZ9000 交易日誌查詢
        role.getMenuItems().add(item);
        
        
        item = new MenuItem();
        item.setMenuItemPk(new Long(38));// SOEZ9000 登入密碼修改
        role.getMenuItems().add(item);
        
        item = new MenuItem();
        item.setMenuItemPk(new Long(39));// SOEZ9000 強迫登出功能
        role.getMenuItems().add(item);
        */
        
        roleDao.save(role);

        user.addRole(role);
        userDao.save(user);
        
        
        if (!Group.GROUP_TYPE_SCHOOL.equals(group.getGroupType()))
        {
            // 新增自動產生繳款單設定
            FormatDefinition fd = new FormatDefinition();
            fd.setGroup(group);
            fd.setBatchUsed(Boolean.TRUE);
            fd.setDeleted(Boolean.FALSE);
            fd.setFormatName("自動產生繳款單設定");
            fd.setFormatType(new Integer(1)); //轉入類別 1:繳費單資料
            fd.setJrxmlPath(reportTemplateDirectory +"/community.jrxml");
            
            List<ColumnDefinition> defaultColumnDefinitions = new ArrayList<ColumnDefinition>();
            fd.setColumnDefinitions(defaultColumnDefinitions);
            
            int pos = 0;
            ColumnDefinition cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("virtualAccount");
            cd.setColumnTitle("繳費帳號");
            cd.setColumnType("1");
            cd.setRequired(Boolean.TRUE);
            cd.setHeader(Boolean.TRUE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 16));//length = 16       
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("totalAmount");
            cd.setColumnTitle("應繳合計");
            cd.setColumnType("2");
            cd.setRequired(Boolean.TRUE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 7)); //length = 7
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
                   
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("payDue");
            cd.setColumnTitle("繳費期限");
            cd.setColumnType("3");
            cd.setRequired(Boolean.TRUE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 8)); //length = 8
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("paymentName");
            cd.setColumnTitle("帳單名稱");
            cd.setColumnType("1");
            cd.setRequired(Boolean.TRUE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 30)); //length = 30
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("period");
            cd.setColumnTitle("期別");
            cd.setColumnType("1");
            cd.setRequired(Boolean.TRUE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 10)); //length = 10
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("payerName");
            cd.setColumnTitle("繳款人姓名");
            cd.setColumnType("1");
            cd.setRequired(Boolean.TRUE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 20)); //length = 20
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("payerId");
            cd.setColumnTitle("繳款人編號");
            cd.setColumnType("1");
            cd.setRequired(Boolean.TRUE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 10)); //length = 10
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("payerEmail");
            cd.setColumnTitle("繳款人E-Mail");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 50)); //length = 50
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("payerBirthday");
            cd.setColumnTitle("繳款人生日");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 8)); //length = 8
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("payerAddress");
            cd.setColumnTitle("繳款人住址");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 70)); //length = 70
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("payerTelNo");
            cd.setColumnTitle("繳款人電話");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 20)); //length = 20
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("payerCellNo");
            cd.setColumnTitle("繳款人手機");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 10)); //length = 10
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("paymentNote1");
            cd.setColumnTitle("注意事項");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 470)); //length = 470
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("paymentNote2");
            cd.setColumnTitle("最新消息");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 300)); //length = 300
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("paymentNote3");
            cd.setColumnTitle("備註");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 100)); //length = 100
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setHeader(Boolean.TRUE);
            cd.setCanDelete(Boolean.FALSE);
            cd.setCanModify(Boolean.FALSE);
            defaultColumnDefinitions.add(cd);
            
            
            // -- 明細, 要有6個明細
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("itemName");
            cd.setColumnTitle("繳費項目");
            cd.setColumnType("1");
            cd.setRequired(Boolean.TRUE);
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 20)); //length = 20
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("amount");
            cd.setColumnTitle("金額");
            cd.setColumnType("2");
            cd.setRequired(Boolean.TRUE);
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 7)); //length = 7
            defaultColumnDefinitions.add(cd);

            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("itemName");
            cd.setColumnTitle("繳費項目");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 20)); //length = 20
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("amount");
            cd.setColumnTitle("金額");
            cd.setColumnType("2");
            cd.setRequired(Boolean.FALSE);
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 7)); //length = 7
            defaultColumnDefinitions.add(cd);

            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("itemName");
            cd.setColumnTitle("繳費項目");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 20)); //length = 20
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("amount");
            cd.setColumnTitle("金額");
            cd.setColumnType("2");
            cd.setRequired(Boolean.FALSE);
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 7)); //length = 7
            defaultColumnDefinitions.add(cd);

            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("itemName");
            cd.setColumnTitle("繳費項目");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 20)); //length = 20
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("amount");
            cd.setColumnTitle("金額");
            cd.setColumnType("2");
            cd.setRequired(Boolean.FALSE);
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 7)); //length = 7
            defaultColumnDefinitions.add(cd);

            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("itemName");
            cd.setColumnTitle("繳費項目");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 20)); //length = 20
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("amount");
            cd.setColumnTitle("金額");
            cd.setColumnType("2");
            cd.setRequired(Boolean.FALSE);
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 7)); //length = 7
            defaultColumnDefinitions.add(cd);

            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("itemName");
            cd.setColumnTitle("繳費項目");
            cd.setColumnType("1");
            cd.setRequired(Boolean.FALSE);
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 20)); //length = 20
            defaultColumnDefinitions.add(cd);
            
            cd = new ColumnDefinition();
            cd.setFormatDefinition(fd);
            cd.setColumnName("amount");
            cd.setColumnTitle("金額");
            cd.setColumnType("2");
            cd.setRequired(Boolean.FALSE); 
            cd.setHeader(Boolean.FALSE);
            cd.setDisplay(Boolean.FALSE);
            cd.setQuery(Boolean.FALSE);
            cd.setBeginIndex(pos+1);
            cd.setEndIndex((pos = pos + 7)); //length = 7
            defaultColumnDefinitions.add(cd);
            

            // 設定特殊代碼 XXX
            Set<CommissionCodeTable> commissionCodeTables = new HashSet<CommissionCodeTable>();
            fd.setCommissionCodeTables(commissionCodeTables);
            List<CommissionCodeTable> codes = commissionCodeTableDao.queryCommissionCodeTables("XXX", null);
            if (null == codes || 0 == codes.size())
                throw new RuntimeException("請先設定特殊手續費代碼XXX");
            CommissionCodeTable code = new CommissionCodeTable();
            code.setCommissionCodePk(codes.get(0).getCommissionCodePk());
            commissionCodeTables.add(code);
            
            formatDefinitionDao.save(fd);
        }
                
        return group;
    }


    /* (non-Javadoc)
     * @see com.feib.soeasy.service.GroupService#deleteGroup(com.feib.soeasy.model.Group)
     */
    @Override
    public void deleteGroup(Group group) {
        formatDefinitionDao.deleteByGroup(group);
        realAccountDao.deleteByGroup(group);
        roleDao.deleteByGroup(group);
        userDao.deleteByGroup(group);
        this.groupDao.deleteById(group.getGroupPk());
    }

}
